﻿// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Main
{
	using System;
	using System.ComponentModel;
    using System.Text.RegularExpressions;
	using System.Windows.Forms;

	using CE.API;

	using WeifenLuo.WinFormsUI.Docking;

	public sealed class ErrorList : DockContent, ICEPluginTab
	{
		#region Fields

		private SourceEditor activeTextEditor;
		private ColumnHeader columnHeader1;
		private ColumnHeader columnHeader2;
		private ColumnHeader columnHeader3;
		private ColumnHeader columnHeader4;
		private ColumnHeader columnHeader5;
		private ColumnHeader columnHeader6;
		private IContainer components;
		private ImageList imgList;
		private ListView listView1;

		#endregion Fields

		#region Constructors

		public ErrorList(SourceEditor txtEditor)
		{
			InitializeComponent();
			TabText = "Error List";
			listView1.Items.Clear();
			IsDisposed = false;
			if(txtEditor!= null)
				activeTextEditor = txtEditor;
			ToolStripManager.Renderer = new CE.CustomControls.Office2007Renderer();
            listView1.ItemActivate += listView1_ItemActivate;
		}

		#endregion Constructors

		#region Properties

		public bool AbleToCopy
		{
			get { return false; }
		}

		public bool AbleToCut
		{
			get { return false; }
		}

		public bool AbleToDelete
		{
			get { return false; }
		}

		public bool AbleToPaste
		{
			get { return false; }
		}

		public bool AbleToRedo
		{
			get { return false; }
		}

		public bool AbleToSave
		{
			get { return false; }
		}

		public bool AbleToSelectAll
		{
			get { return false; }
		}

		public bool AbleToUndo
		{
			get { return false; }
		}

		public string FileName
		{
			get { return ""; }
		}

		public ICEPluginHost Host
		{
			get; set;
		}

		public new bool IsDisposed
		{
			get; set;
		}

		public bool NeedsSaving
		{
			get { return false; }
		}

		public string Selection
		{
			get { return ""; }
		}

		#endregion Properties

		#region Methods

		public void ClearList()
		{
			if (listView1.Items.Count > 0)
				listView1.Items.Clear();
		}

		public bool CloseTab()
		{
			return false;
		}

		public void Copy()
		{
		}

		public void Cut()
		{
		}

		public void Delete()
		{
		}

		public void Duplicate()
		{
		}

		public bool FindNext( Regex reg, bool searchUp)
		{
			return false;
		}

		public void MarkAll( Regex reg)
		{
		}

		public void Paste()
		{
		}

		public void Print(bool showDialog)
		{
		}

		public void Redo()
		{
		}

		public void ReplaceAll( Regex reg,  string replaceWith)
		{
		}

		public void ReplaceNext( Regex reg,  string replaceWith, bool searchUp)
		{
		}

		public void Save()
		{
		}

		public void SaveAs( string filePath)
		{
		}

		public void SelectAll()
		{
		}

		public void SelectWord(int line, int offset, int wordLeng)
		{
		}

		public void ShowErrors(int imgIndex, string line, string col, string erNum,
		                       string mess, string file, int i)
		{
			var listviewitem = new ListViewItem {ImageIndex = imgIndex};
			listviewitem.SubItems.Add(line);
			listviewitem.SubItems.Add(col);
			listviewitem.SubItems.Add(erNum);
			listviewitem.SubItems.Add(mess);
			listviewitem.SubItems.Add(file);
			listView1.Items.Add(listviewitem);
		}

		public void Undo()
		{
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
				components.Dispose();
			if (Controls.Count > 0) {
				for (short index = 0; index < Controls.Count; ++index)
					Controls[index].Dispose();
			}
			base.Dispose(disposing);
		}

		private void ErrorList_FormClosing(object sender, FormClosingEventArgs e)
		{
			IsDisposed = true;
			Dispose(true);
		}

        private void listView1_ItemActivate(object sender, EventArgs e)
		{
			ListViewItem item = listView1.SelectedItems[0];
			if (null != activeTextEditor) {
				activeTextEditor.Goto(
				        (item.SubItems[1].Text == "0") ? int.Parse(item.SubItems[1].Text) : int.Parse(item.SubItems[1].Text) - 1,
				        (item.SubItems[2].Text == "0") ? int.Parse(item.SubItems[2].Text) : int.Parse(item.SubItems[2].Text) - 1);
				activeTextEditor.Activate();
			}
        }

        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("");
			System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("");
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ErrorList));
			this.listView1 = new System.Windows.Forms.ListView();
			this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
			this.imgList = new System.Windows.Forms.ImageList(this.components);
			this.SuspendLayout();
			//
			// listView1
			//
			this.listView1.Activation = System.Windows.Forms.ItemActivation.TwoClick;
			this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
			                                        this.columnHeader6,
			                                        this.columnHeader1,
			                                        this.columnHeader2,
			                                        this.columnHeader3,
			                                        this.columnHeader4,
			                                        this.columnHeader5
							});
			this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.listView1.FullRowSelect = true;
			this.listView1.GridLines = true;
			this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
			                                      listViewItem1,
			                                      listViewItem2
						      });
			this.listView1.Location = new System.Drawing.Point(0, 0);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(1036, 205);
			this.listView1.SmallImageList = this.imgList;
			this.listView1.TabIndex = 0;
			this.listView1.UseCompatibleStateImageBehavior = false;
			this.listView1.View = System.Windows.Forms.View.Details;
			//
			// columnHeader6
			//
			this.columnHeader6.Text = "";
			this.columnHeader6.Width = 30;
			//
			// columnHeader1
			//
			this.columnHeader1.Text = "Line";
			//
			// columnHeader2
			//
			this.columnHeader2.Text = "Column";
			//
			// columnHeader3
			//
			this.columnHeader3.Text = "Error";
			//
			// columnHeader4
			//
			this.columnHeader4.Text = "Description";
			this.columnHeader4.Width = 600;
			//
			// columnHeader5
			//
			this.columnHeader5.Text = "File";
			this.columnHeader5.Width = 125;
			//
			// imgList
			//
			this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
			this.imgList.TransparentColor = System.Drawing.Color.Transparent;
			this.imgList.Images.SetKeyName(0, "warning_icon.png");
			this.imgList.Images.SetKeyName(1, "error_icon.png");
			//
			// ErrorList
			//
			this.ClientSize = new System.Drawing.Size(1036, 205);
			this.Controls.Add(this.listView1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "ErrorList";
			this.ResumeLayout(false);
		}

		#endregion Methods
	}
}